<?php
header("Content-type:text/html;charset=utf8");//字符编码设置

error_reporting(0);

$cid = $_POST['cid'];
$csn = $_POST['csn'];
$teatext = $_POST['teatext'];

if($cid!=NULL && $csn!=NULL &&$teatext!=NULL){
    $conn = mysqli_connect('localhost:3306','root','124938');
    mysqli_select_db($conn,'schedule');
    mysqli_query($conn,'SET NAMES UTF8');
    $sql = " insert into notice (scid,scsn,teatext) values('$cid','$csn','$teatext')";

    if ($conn->query($sql) == TRUE) {
        echo "<script>alert('插入成功，请刷新')</script>";
    }
    else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    $conn->close();

}

?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>通知公告</title>
    <link rel="stylesheet" href="style.css" />
    <style>
        body {
            background-image: url(images/background1.png);
            background-repeat: no-repeat;
            background-position: center top;
            background-size: cover;
        }
    </style>
</head>


<body>
    <div class="header w">
        <div class="logo">
            <img src="images/logo.png" alt="" />
        </div>

        <div class="nav">
            <ul>
                <li><a href="index.html" target="_self">学生课表</a></li>
                <li><a href="classroom.html" target="_self">教室课表查询</a></li>
                <li><a href="teacher.html" target="_self">教师课表查询</a></li>
                <li><a href="stunotes.html" target="_self">学生笔记</a></li>
                <li><a href="notice.html" target="_self">通知公告</a></li>
            </ul>
        </div>
    </div>

    <div class="header w">
        <?php

        echo "<table border=6 frame = void align = center width = 1200px height = 100px cellspacing = 0px cellpadding = 10 px>";
        echo "  <tr height = 40px align = center>
                     <td ></td><td colspan = 4 color = red><font color = \"red\"><b>通知公告</b></font></td>
                </tr>";
        echo "  <tr height = 50px align = center>
                     <th width = 110px></th><th><font color = blue>课程名</font></th><th><font color = blue>任课教师</font></th><th><font color = blue>公告内容</font></th>
                </tr>";


        $conn = mysqli_connect('localhost:3306','root','124938');
        mysqli_select_db($conn,'schedule');
        mysqli_query($conn,'SET NAMES UTF8');

        $sql = " select * from stuclass,notice where notice.scid=stuclass.scid and notice.scsn=stuclass.scsn";
        $res = mysqli_query($conn,$sql);
//        $row=mysqli_fetch_array($res);
        $i=1;
        while($row=@mysqli_fetch_array($res)){
            echo "<tr height = 100px align = center>";
            for ($j = 0; $j < 4; $j++) {
                if ($j == 0) echo "<td ><font color = blue><b> $i </b></font></td>";
                else if($j == 1){
                    echo "<td>$row[2]<br></td>";
                }
                else if($j == 2){
                    echo "<td>$row[3]<br></td>";
                }
                else{
                    echo "<td>$row[15]<br></td>";
                }
            }
            $i++;
            echo "</tr>";
        }


        echo "</table>";
        ?>
    </div>
</body>
</html>
<?php
    echo "<script>alert('公告显示成功！！')</script>";

?>
